<template>
  <view class="box">
    <!-- 导航 -->
    <uv-navbar title="新增地址" bgColor="#f7f6fa" height="44px" titleStyle="{font-weight: bold;font-size: 1.1rem;}"
      @click="goback"></uv-navbar>
    <!-- 地址 -->
    <view class="list" v-for="(item,index) in list" :key="item.id">
      <view class="all">
        <view class="all-left">
          <image src="../../static/image/位置.png" mode=""></image>
        </view>
        <view class="all-right">
          <view class="all-top">
            <view class="all-top1">{{item.name}}
              <view style="font-size:0.8rem;color: #bdbdbd;">{{item.mobile}}</view>
            </view>

          </view>

          <view class="all-bottom">{{item.area}}-{{item.address}}</view>
        </view>
      </view>
      <view class="group">
        <uv-radio-group>
          <uv-radio-group v-model="radiovalue">
            <uv-radio :name="item.switch" label="默认地址" activeColor="#1d8b8c"></uv-radio>
          </uv-radio-group>
        </uv-radio-group>
        <view class="group1">
          <uv-icon name="trash" size="22px" style="margin-right: 20rpx;" @click="del(item.id)"></uv-icon>
          <uv-icon name="edit-pen" size="22px" @click="goNewaddress(item.id)"></uv-icon>

        </view>
      </view>
    </view>
    <!-- 按钮 -->
    <view class="btn">
      <uv-button @click="goNewaddress" type="primary" color="#008c8c" shape="circle" text="新增地址"></uv-button>
    </view>
  </view>
</template>

<script>
  import {
    uniRequest
  } from "../../utils/request.js"
  export default {
    data() {
      return {
        radiovalue: '是默认地址',
        list: ''
      }
    },
    created() {
      const that = this
      uniRequest('address/index?server=1', function(err, data) {
        if (err) {
          // 错误
          console.log(err)
        } else {
          console.log('"成功了"', data)
          that.list = data
        }
      }, 'GET', {

      });
    },
    methods: {
      del(id){
        
        console.log(id)
        uniRequest('address/delete?server=1', function(err, data) {
          if (err) {
            // 错误
            console.log(err)
          } else {
            console.log('"成功了"', data)
          }
        }, 'GET', {
          id: id
        });
      },
      goNewaddress(id) {
        uni.navigateTo({
          url: `/pages/newaddress/newaddress?id=${JSON.stringify(id)}`
        })
      },
      goback() {
        uni.navigateBack({
          delta: 1
        });
      }
    }
  }
</script>

<style lang="scss">
  @import url("deliveryaddress.scss");
</style>